package top.archiesean.sqlSession;

import top.archiesean.config.XMLConfigBuilder;
import top.archiesean.pojo.Configuration;
import top.archiesean.sqlSession.impl.DefaultSqlSessionFactory;

import java.io.InputStream;

/**
 * 会话对象工厂类
 *
 * @author ArchieSean
 * @create 2023/7/11
 */
public class SqlSessionFactoryBuilder {

    /**
     * 用于构建sqlSessionFactory工厂
     *
     * @param in 字节输入流
     * @return sqlSessionFactory
     */
    public SqlSessionFactory build(InputStream in) {
        //1.使用dom4j去解析配置文件，将解析出来的内容封装到Configuration当中
        XMLConfigBuilder builder = new XMLConfigBuilder();
        Configuration configuration = builder.parseConfig(in);
        //2. 创建sqlSessionFactory对象
        return new DefaultSqlSessionFactory(configuration);
    }
}
